package com.higold.cloud.mvp.presenter

import com.higold.cloud.base.BasePresenter
import com.higold.cloud.mvp.contract.AchieveDetailContract
import com.higold.cloud.mvp.model.AchieveDetailModel
import com.higold.cloud.net.exception.ExceptionHandle

/**
 *    author : lxz
 *    date   : 2019/8/30 17:15
 *    desc   :
 */
class AchieveDetailPresenter : BasePresenter<AchieveDetailContract.View>(), AchieveDetailContract.Presenter {

    private val achieveModel by lazy { AchieveDetailModel() }

    override fun getAchieveDetail(user_code: String) {
        checkViewAttached()
        mRootView?.showLoading()
        val disposable = achieveModel.requestAchieveDetail(user_code)
                .subscribe({ achieve ->
                    mRootView?.setAchieveDetail(achieve)
                }, { throwable ->
                    //处理异常
                    mRootView?.showError(ExceptionHandle.handleException(throwable), ExceptionHandle.errorCode)
                })
        addSubscription(disposable)
    }
}